<?php
/*
 * test_metabase_auto_complete.php
 *
 * @(#) $Header: /home/mlemos/cvsroot/forms/test_metabase_auto_complete.php,v 1.2 2006/12/20 06:21:17 mlemos Exp $
 *
 */

	define("METABASE_PATH","./ajax/metabase");
	require(METABASE_PATH."/metabase_database.php");
	require(METABASE_PATH."/metabase_interface.php");
	require('./ajax/forms.php');
	require('./ajax/form_ajax_submit.php');
	require('./ajax/form_auto_complete.php');
	require('./ajax/form_metabase_auto_complete.php');

	$arguments=array(
		"Type"=>"mysql",
		"User"=>"root",
		"Password"=>"mysql1",
		"Database"=>"medicus",
		"IncludePath"=>METABASE_PATH,
		"Debug"=>"error_log",
	);
	MetabaseSetupDatabase($arguments,$database);

	$form=new form_class;
	$form->NAME='auto_complete_form';
	$form->METHOD='POST';
	$form->ACTION='';
	$form->debug='error_log';
	$form->AddInput(array(
		'TYPE'=>'text',
		'ID'=>'location',
		'NAME'=>'location',
		'SIZE'=>60,
		'LABEL'=>'Nazwa <u>L</u>eku',
		'ACCESSKEY'=>'L',
		'VALUE'=>'',
		'ExtraAttributes'=>array(
			'autocomplete'=>'off',
			'title'=>'Leki.',
		)
	));
	$form->AddInput(array(
		'TYPE'=>'button',
		'NAME'=>'show_locations',
		'ID'=>'show_locations',
		'VALUE'=>'...',
		'ExtraAttributes'=>array(
			'title'=>'Click to show all locations.'
		)
	));
	$form->AddInput(array(
		'TYPE'=>'custom',
		'ID'=>'complete_location',
		'NAME'=>'complete_location',
		'CustomClass'=>'form_metabase_auto_complete_class',
		'CompleteInput'=>'location',
		'CompleteMinimumLength'=>1,
		'Dynamic'=>1,
		'ShowButton'=>'show_locations',
		"Connection"=>$database,
		"CompleteValuesQuery"=>"SELECT nazwa FROM sl_bloz WHERE nazwa {BEGINSWITH} ORDER BY nazwa",
		"CompleteValuesLimit"=>10,
		'FeedbackElement'=>'complete_location_feedback',
		'SubmitFeedback'=>' <img src="indicator.gif" width="16" height="16" alt="Looking up for locations" title="Looking up for locations" /> ',
		'CompleteFeedback'=>' <img src="indicator.gif" width="16" height="16" style="visibility: hidden;" /> ',
		'MenuClass'=>'groovymenu',
		'MenuStyle'=>'',
		'ItemClass'=>'groovyitem',
		'ItemStyle'=>'',
		'SelectedItemClass'=>'groovyselecteditem',
		'SelectedItemStyle'=>'',
	));

	/*
	 * This code is necessary to handle the requests for fetching
	 * auto-complete values.
	 */
	$form->HandleEvent($processed);
	if($processed)
		exit;

	$form->ConnectFormToInput('location', 'ONLOAD', 'Focus', array());

	$onload=HtmlSpecialChars($form->PageLoad());

?>

<body onload="<?php echo $onload; ?>" bgcolor="#cccccc">

<?php
	$error_message='';
	$form->StartLayoutCapture();
	$title='Leki';
	$body_template='form_locations_auto_complete_body.html.php';
	include('./ajax/templates/form_frame.html.php');
	$form->EndLayoutCapture();

	$form->DisplayOutput();

	MetabaseCloseSetup($database);
?>
